	<?php 
					$daction = $_SESSION['action'];
		$lang = $_SESSION['lang'];

		//Get information of document
		$query = mysql_query("select a.Tile,a.Content,a.Timecreate,a.TripDate,a.purpose,a.Content2,a.Description,a.comment,a.IDEmployee,
				e.Fullname,a.IDGroupApprove,a.IDStatus
				from approvedoc a inner join employee e on a.IDEmployee = e.IDEmployee 
				where a.IDApproveDoc = '$id'");
		while ($row = mysql_fetch_array($query))
		{
			$dcomment = $row[comment];
			$dtitle = $row[Tile];
			$ddescription = $row[Description];
			$dtime = $row[Timecreate];
			$duser = $row[Fullname];
			$demployeeperforment = $row[EmployeePerforment];
			$dtripdate = $row[TripDate];
			$dlocation = $row[Location];
			$dtotaltime = $row[TotalTime];
			$didgroupapprover = $row[IDGroupApprove];
			$dcontent = $row[Content];
			$dcontent2 = $row[Content2];
			$dpurpose = $row[purpose];
			$didemployee = $row[IDEmployee];
			$dstatus = $row[IDStatus];
		}
		$flagmysending=false;
		if($daction == "my_sending"){
			$result=mysql_query("select listapprove.ID FROM listapprove WHERE IDGroupApprove='".$didgroupapprover."' and (IDStatus = 1 or IDStatus = 3 or IDStatus > 9)");
			if(mysql_num_rows($result)==0){
				$flagmysending=true;
			}
		}
		$queryEmployee = mysql_query("SELECT e.FullName,dl.DepartmentName,e.Position
				FROM employee e INNER JOIN department_lang dl ON dl.IDDepartment = e.IDDepartment
				WHERE e.IDEmployee = '$didemployee' AND dl.LangID = '$lang'");
		while ($row = mysql_fetch_array($queryEmployee))
		{
			$dnameemployee = $row[FullName];
			$dnamedepartment = $row[DepartmentName];
			$dposition = $row[Position];
		}
		$query1 = mysql_query("SELECT l.IDStatus,l.DateApprove,e.Fullname,l.Description,l.IDEmployee FROM listapprove l
                    						INNER JOIN employee e ON l.IDEmployee = e.IDEmployee
                    						WHERE CONVERT(l.IDGroupApprove USING utf8) = CONVERT('$didgroupapprover' USING utf8)
                    						ORDER BY l.Order ASC");
		if(isset($_SERVER['HTTP_REFERER'])){
			$url=split('\&page=',$_SERVER['HTTP_REFERER']);
			$_SESSION['backpage']=$url[0];
		}
		
	?>
	<div class="nav_top">
       		<div class="nav_tit"><?php echo $l_e_approval;?></div>     
            <div class="rehome"><a href="mainPhone.php"><?php echo $l_menu?></a></div>       
       	</div>
	<form action="approve-handle.php" method="get">
		<input type="hidden" name="id" value="<?=$id?>" />
		<input type="hidden" name="type" value="<?=$type?>" />
	<div class="main_content">
	
            <ul class="top_but">
				<?php if($daction=="re_not_approve"  || $daction=="my_saved"){?>
				<li><?php if(isset($_REQUEST['page'])){?>
						<input type="hidden" name="page" value="<?=$_REQUEST['page']?>" />
						<a href="<?=$_SESSION['backpage']?>&page=<?=$_REQUEST['page']?>"><img src="images/back.png" alt="" /></a>
					<?php }else{?>
						<a href="<?=$_SESSION['backpage']?>"><img src="images/back.png" alt="" /></a>
					<?php }?></li>
				<?php }else{?>
							<li><?php if(isset($_REQUEST['page'])){?>
									<input type="hidden" name="page" value="<?=$_REQUEST['page']?>" />
									<a href="<?=$_SESSION['backpage']?>&page=<?=$_REQUEST['page']?>"><img src="images/back.png" alt="" /></a>
								<?php }else{?>
									<a href="<?=$_SESSION['backpage']?>"><img src="images/back.png" alt="" /></a>
								<?php }?></li>
				<?php }?>
				<?php if($daction=="mybin_senddoc"){
			$_SESSION['idGroup']=$didgroupapprover;
			$_SESSION['id_employee']=$id_employee;
	?>
				<li><input type="submit" name="Restore" value="" style="background:url(images/restore.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /></li>
	<?php }?>
	<?php if($daction=="re_not_approve"){
			$_SESSION['idGroup']=$didgroupapprover;
			$_SESSION['id_employee']=$id_employee;
	?>
				
				
				<li><input type="submit" name="Approve" value="" style="background:url(images/ok.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /></li>
				<li><input type="submit" name="Reject" value="" style="background:url(images/deny.png) no-repeat; width:36px; height:36px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /></li>
	<?php }?>
	<?php
		 if($daction == "re_reference_waiting"){
			$_SESSION['idGroup']=$didgroupapprover;
			$_SESSION['id_employee']=$id_employee;
	?>
				<li><input type="submit" name="Accept" value="" style="background:url(images/ok.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /></li>
	<?php }?>
	<?php
		 if($daction == "my_declined" || $flagmysending==true){
			$_SESSION['idGroup']=$didgroupapprover;
			$_SESSION['id_employee']=$id_employee;
	?>
				<li><input type="submit" name="Delete" value="" style="background:url(images/trash.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /></li>
	<?php }?>
				
			</ul>
		<table class="tcontent" cellpadding="5" cellspacing="0">
			<?php 
               		if($daction == "re_not_approve"){
               ?> 	
              <tr>
                <td class="col_left" width="15%"><?=$l_comment?></td>
                <td colspan="3" style="padding: 1px 1px"><textarea name="textarea" cols="5" rows="3" style="width:99%; border:1px solid #c4c0c9"></textarea></td>
              </tr>
              <?php } ?>
			<tr>
				<td class="col_left" width="15%"><?=$l_approver?></td>
				<td colspan="3">
				<table class="tcontent" cellpadding="5" cellspacing="0">
                        	
                    				<?
                    				//Get group approver
                    				
                    				
                    				$i=1;
                    				while ($row = mysql_fetch_array($query1))
                    				{
                    					$dnameapprover = $row[Fullname];
                    					$ddateapproved = $row[DateApprove];
                    					$dcommentm=$row[Description];
                    					$didEmployee=$row[IDEmployee];
                    					if ($row[IDStatus] == 1){
	                    					$dstatus=$l_status_complete;
	                    				} else if ($row[IDStatus] == 2){
	                    					$dstatus=$l_status_pending;
	                    				}else if ($row[IDStatus] == 3){
	                    					$dstatus=$l_status_declined;
	                    				}else if ($row[IDStatus] == 4){
	                    					$dstatus=$l_status_saved;
	                    				}else if ($row[IDStatus] == 5){
	                    					$l_status_reference;
	                    				}
                    				?>
                    				
                    				<tr>	
                    					<td rowspan="2"  style="padding: 5px 5px;color:blue;width: 100px"><?=$l_step?> <?=$i?> </td>
                    					<td  style="padding: 5px 5px; width: 500px" >
		                    				<span style="display: block;">
		                    					<b><?=$dnameapprover?></b>_<?=$dstatus?> <?=$ddateapproved?>
		                    				</span>
	                    				</td>
	                    				<td style="padding: 5px 5px"> <div align="left"><?=$l_reference?> :
		                                	<?
		                    				//Get list references
		                    				$query2 = mysql_query("SELECT e.Fullname FROM list_reference l
		                    						INNER JOIN employee e ON l.id_employee = e.IDEmployee
		                    						WHERE CONVERT(l.id_group USING utf8) = CONVERT('$didgroupapprover' USING utf8) AND
		                    									l.id_manager='$didEmployee'") ;
		                    				
		                    				while ($row1 = mysql_fetch_array($query2))
		                    				{
		                    					$dnamereferences = $row1[Fullname];
		                    				?>
		                    				<b><?=$dnamereferences?></b>;
		                    				<?
		                    				}
		                    				?>
		                                
		                               </div> </td>
                    				</tr>
                    				<?php if($ddateapproved ==null){?>
                    				<tr >
                    				</tr>
                    				<?php }else{?>	
                    				<tr >
                    					<td colspan="2" style="padding: 5px 5px"><div align="left"><b><?=$l_comment?> : </b><?=$dcommentm?> </div></td>
                    				</tr>
                    				<?php }?>
                    				
                    				<?
                    					$i++;
                    				}
                    				?>
                    				
                        </table> 
				</td>
			</tr>
			<tr>
				<td class="col_left" width="15%"><?=$l_department?>/<?=$l_employee?></td>
				<td colspan="3"><?=$dnameemployee?> (<?=$dnamedepartment?>)</td>
			</tr>
			<tr>
				<td class="col_left" width="15%"><?=$l_title?></td>
				<td colspan="3"><?=$dtitle?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_content?></td>
				<td colspan="3">
					<?=$dcontent?>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_created_date?></td>
				<td><?=$dtime?></td>
				<td class="col_left"><?=$l_purchase_date?></td>
				<td><?=$dtripdate?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_purpose?></td>
				<td colspan="3"><?=$dpurpose?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_project?></td>
				<td colspan="3"><?=$dcontent2?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_description?></td>
				<td colspan="3"><?=$ddescription?></td>
			</tr>
		</table>
		<table class="tcontent" cellpadding="5" cellspacing="0" style="width: 100%">
			<tr class="col_left" style="border-bottom: 1px solid #ccc;">
				<th width="3%" style="padding:4px; border-bottom: 1px solid #C4C0C9; border-right: 1px solid #C4C0C9; text-align:center; color:#333; height:36px"><?=$l_no?></th>
				<th width="25%" style="padding:4px; border-bottom: 1px solid #C4C0C9; border-right: 1px solid #C4C0C9; text-align:center; color:#333; height:36px"><?=$l_product_item?></th>
				<th width="25%" style="padding:4px; border-bottom: 1px solid #C4C0C9; border-right: 1px solid #C4C0C9; text-align:center; color:#333; height:36px"><?=$l_company_name?></th>
				<th width="8%" style="padding:4px; border-bottom: 1px solid #C4C0C9; border-right: 1px solid #C4C0C9; text-align:center; color:#333; height:36px"><?=$l_quantity?></th>
				<th width="13%" style="padding:4px; border-bottom: 1px solid #C4C0C9; border-right: 1px solid #C4C0C9; text-align:center; color:#333; height:36px"><?=$l_price?></th>
				<th width="13%" style="padding:4px; border-bottom: 1px solid #C4C0C9; border-right: 1px solid #C4C0C9; text-align:center; color:#333; height:36px"><?=$l_price_vat?></th>
				<th width="13%" style="padding:4px; border-bottom: 1px solid #C4C0C9; border-right: 1px solid #C4C0C9; text-align:center; color:#333; height:36px"><?=$l_total_amount?></th>
			</tr>
			<?
			$querybuy = mysql_query("select * from buying_document where document_id = '$id'");
			$dtotalamountt = 0;
			$i=1;
			while ($row = mysql_fetch_array($querybuy))
			{
				$dproductitem = $row[name];
				$dcompanyname = $row[company];
				$dquantity = $row[amount];
				$dprice = $row[price];
				$dpricevat = $row[vat];
				$dtotalamount = $row[total];
				$dtotalamountt = $dtotalamount + $dtotalamountt;
			?>
			<tr>
				<td><?=$i?></td>
				<td><?=$dproductitem?></td>
				<td><?=$dcompanyname?></td>
				<td><?=$dquantity?></td>
				<td><?=$dprice?></td>
				<td><?=$dpricevat?></td>
				<td style="text-align:right;padding-right:10px;"><?=$dtotalamount?></td>
			</tr>
			<?
			$i++;
			}
			?>
		</table>
		<table class="tcontent" cellpadding="5" cellspacing="0">
			<tr>
				<td class="col_left" style="width:15%"><?=$l_total_amount?></td>
				<td style="width:85%;text-align:right;font-weight:bold;padding-right:10px;"><?=$dtotalamountt?></td>
			</tr>
			<tr>
				<td class="col_left" style="width: 15%;"><?=$l_comment?></td>
				<td style="text-align:left;width: 85%"><?=$dcomment?></td>
			</tr>
		</table>
	</div>
</form>
    <?php mysql_close($connection);?>